/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

function toggle(start, nb) {
	var img = document.getElementById('plus_minus_img_' + start);
	var td = img.parentNode;
	
	if (td.className == 'seperator') {
		td.className='seperator seperatorSel';
	} else {
		td.className='seperator';
	}
	
	
	for (var i=start ; i<parseInt(start,10)+parseInt(nb,10) ; i++) {
		var tr = document.getElementById('toggable_line_' + i);
		var t_img = tr.getElementsByTagName('img');
		
		if (tr.style.display == 'none') {
			tr.style.display='';
			
			for (var j=0 ; j<t_img.length ; j++) {
				if (t_img[j].title != "") {
					t_img[j].src=t_img[j].title;
					t_img[j].title='';
				}
			}
			
			if (i == start) {
				img.src = 'Interface/Buttons/UI-MinusButton-Up.gif';
			}
		} else {
			tr.style.display='none';
			
			if (i == start) {
				img.src = 'Interface/Buttons/UI-PlusButton-Up.gif';
			}
		}
	}
}

function more_less(id) {
	var more = document.getElementById(id + "_more");
	var less = document.getElementById(id + "_less");
	var chars = document.getElementById(id + "_chars");
	
	if ( more.style.display == "" ) {
		more.style.display = "none";
		less.style.display = "";
		chars.style.display = "";
	} else {
		more.style.display = "";
		less.style.display = "none";
		chars.style.display = "none";
	}
}

// Wowtable browsing

var wt_elements_id;
var wt_elements_n=10;
var wt_elements_t;

function wt_initTable(id) {
	wt_elements_id = id;

	var i=1;
	var el;
	
	do {
		el = document.getElementById(wt_elements_id + i);
		if (el==null) {
			break;
		}
		
		if (i>wt_elements_n) {
			el.style.display='none';
		} else {
			el.style.display='';
		}
		
		i++;
	} while (true);
	
	wt_elements_t=i;
	
	wt_count(1);
}

function wt_next() {
	var i=1;
	var el;
	var el2;
	
	do {
		el = document.getElementById(wt_elements_id + i);
		if (el==null) {
			return;
		}
		
		if (el.style.display!='none') {
			el2 = document.getElementById(wt_elements_id + (i+wt_elements_n));
			if (el2!=null) {
				for (var j=i ; j<i+wt_elements_n ; j++) {
					wt_hide(j);
					wt_display(j+wt_elements_n);
				}
				wt_count(parseInt(i / wt_elements_n) + 2);
				return;
			}
		}
		
		i++;
	} while (true);
}

function wt_previous() {
	var i=1;
	var el;
	var el2;
	
	do {
		el = document.getElementById(wt_elements_id + i);
		if (el==null) {
			return;
		}
		
		if (el.style.display!='none') {
			if (i==1) {
				return;
			}
			
			for (var j=i ; j<i+wt_elements_n ; j++) {
				wt_hide(j);
				wt_display(j-wt_elements_n);
			}
			wt_count(parseInt(i / wt_elements_n) );
			return;
		}
		
		i++;
	} while (true);
}

function wt_display(id) {
	var el = document.getElementById(wt_elements_id + id);
	
	if (el!=null) {
		el.style.display='';
	}
}

function wt_hide(id) {
	var el = document.getElementById(wt_elements_id + id);
	
	if (el!=null) {
		el.style.display='none';
	}
}

function wt_count(n) {
	var el = document.getElementById('wt_count');
	
	el.innerHTML=n + "/" + (parseInt(wt_elements_t / wt_elements_n) + 1);
}

function wt_change(input) {
	var el = document.getElementById('wt_browse');

	if (input=='') {
		el.style.display='';
		wt_initTable(wt_elements_id);
	} else {
		el.style.display='none';
		
		var i=1;
		var el;
		
		do {
			el = document.getElementById(wt_elements_id + i);
			if (el==null) {
				return;
			}
			
			if (el.innerHTML.toLowerCase().search(">" + input.toLowerCase()) >= 0) {
				el.style.display='';
			} else {
				el.style.display='none';
			}
			
			i++;
		} while (true);
	}
}